package com.rxyb.auth.config;

import com.rxyb.security.common.BusiUserAuthenticationConverter;
import com.rxyb.security.exception.BusiAccessDeniedHandler;
import com.rxyb.security.exception.BusiAuthExceptionEntryPoint;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
import org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.UserAuthenticationConverter;

/**
 * @author YJH
 * @version 1.0
 * @description 资源服务器
 * @date 2020/5/20  14:17
 */
@Configuration
@EnableResourceServer
public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {


    @Override
    public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
        resources.resourceId("authorize-server"); //重点，设置资源id
        DefaultAccessTokenConverter accessTokenConverter = new DefaultAccessTokenConverter();
        UserAuthenticationConverter userTokenConverter = new BusiUserAuthenticationConverter();
        accessTokenConverter.setUserTokenConverter(userTokenConverter);
        resources.authenticationEntryPoint(new BusiAuthExceptionEntryPoint()).accessDeniedHandler(new BusiAccessDeniedHandler());

    }
}
